import QtQuick 2.2

Rectangle {

    property string content: ""
    property string imagepath: ""
    property string imagepath_tmp: ""
    property int flag: 1
    property bool isclick: false
    signal selectItem(int flag, string text, string picpath)
    function changeState(){
        if(flag === 1 && content.search(qsTr("▲")) >=0)
        {
            content = content.substring(0, content.length-1);
            content += qsTr("▼");
            console.log(content);
            color = qsTr("white");
            border.color = qsTr("black"); /*border.width = 1*/
            flag = 0;
        }
        else if(flag === 0 && content.match(qsTr("▼")))
        {
            content = content.substring(0, content.length-1)
            content += qsTr("▲")

            color = qsTr("#C0C0C0")
            flag = 1
            border.color = qsTr("#C0C0C0")
        }

        imagepath_tmp = imagepath.substring(imagepath.indexOf("/", 0)+1, imagepath.length)

    }

 //   signal message(string content, string picpath)

    width: 380; height: 50
   // border.color: "#C0C0C0"; border.width:1
    //color: "lightgreen"
    // 赋值给图片
//    function setImage(path)
//    {
//        image.source = path
//    }

//    // 赋值给文字
//    function setText(content)
//    {
//        text.text = content
//    }

    MouseArea{
        onClicked:
        {
            console.log(qsTr("clicked the item " + content))
            changeState()
            selectItem(flag, content, imagepath_tmp)
//            if(flag === 1 && content.search(qsTr("▲")) >=0)
//            {

//                content = content.substring(0, content.length-1);
//                content += qsTr("▼");
//                console.log(content);
//                color = qsTr("white");
//                border.color = qsTr("black"); /*border.width = 1*/
//                flag = 2;
//            }
//            else if(flag === 2 && content.match(qsTr("▼")))
//            {
//                content = content.substring(0, content.length-1)
//                content += qsTr("▲")

//                color = qsTr("#C0C0C0")
//                flag = 1
//                border.color = qsTr("#C0C0C0")
//            }

//            imagepath_tmp = imagepath.substring(imagepath.indexOf("/", 0)+1, imagepath.length)
//            parent.selectItem(flag, content, imagepath_tmp)
            //parent.message(parent.content, parent.imagepath)
        }

        onPressed:
        {
            if(flag === 1)
                color = qsTr("white")
//                color = qsTr("#C0C0C0")
            else if(flag === 0)
                color = qsTr("#00ACB6")
//                color = qsTr("white")
        }
//        onReleased:
//        {
//            if(flag === 0)
//                color = qsTr("white")
//            else if(flag === 1)
//                color = qsTr("#C0C0C0")
//        }
        anchors.fill: parent
    }
    Row
    {
        spacing: 5
        Image
        {
            id: image
            height: parent.height
            source: imagepath
           // anchors.left:  parent.left
        }
        Text{
            id: text
            height: image.height
            color: parent.enabled?"black":"#888888"
            text: content
            verticalAlignment: Text.AlignVCenter
            fontSizeMode: Text.VerticalFit
            font.pixelSize: 24
            //   text: qsTr("text")
           // anchors.left: image.right           
        }
        anchors.fill: parent
    }


}
